<style lang="scss" rel="stylesheet/scss" scoped>
.bind {
  display: block;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 500px;
  border: 1px solid rgba(215, 215, 215, 1);
  //border: #606060;
  padding: 20px;
}
</style>
<template>
  <el-form ref="form" :model="form" :rules="rules" label-width="80px" size="normal">
    <div style="padding-left: 400px;padding-top: 50px;">
      <h3 class="form-required">绑定天猫账号</h3>
      <div class="bind">
        <el-form-item label="账号" prop="nickName" size="normal">
          <el-input maxlength="30"/>
        </el-form-item>
        <el-form-item label="登录密码" prop="phonenumber" size="normal">
          <el-input maxlength="11"/>
        </el-form-item>
        <el-form-item label="验证码" prop="email" size="normal">
          <el-input maxlength="50"/>
        </el-form-item>
        <el-form-item>
          <el-button size="large" type="primary" @click="" style="margin-left: 120px">确认绑定</el-button>
        </el-form-item>
      </div>
    </div>

  </el-form>
</template>

<style lang="scss" scoped>

</style>

<script>
import {updateUserProfile} from "@/api/jihuo/account";

export default {
  props: {
    user: {
      type: Object
    }
  },
  data() {
    return {
      form: {},
      // 表单校验
      rules: {
        nickName: [
          {required: true, message: "账号不能为空", trigger: "blur"}
        ],
        email: [
          {required: true, message: "登录密码不能为空", trigger: "blur"}
        ],
        phonenumber: [
          {required: true, message: "验证码不能为空", trigger: "blur"},
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的验证码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  watch: {
    user: {
      handler(user) {
        if (user) {
          this.form = {nickName: user.nickName, phonenumber: user.phonenumber, email: user.email, sex: user.sex};
        }
      },
      immediate: true
    }
  },
  methods: {
    submit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateUserProfile(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.user.phonenumber = this.form.phonenumber;
            this.user.email = this.form.email;
          });
        }
      });
    },
    close() {
      this.$tab.closePage();
    }
  }
};
</script>
